<template>
	<view class="container">
		<NavBar title="我的订单"></NavBar>
		<view class="orderList" v-if="!isEmpty">
			<view class="orderCard" v-for="(item,index) of orderList" :key="item._id">
				<view class="orderNum">
					<text class="tip">订单单号：</text>
					<text>{{item.orderNumber}}</text>
				</view>
				<view class="orderCreated">
					<text class="tip">下单时间：</text>
					<text>{{item.created|date('yyyy-mm-dd-hh-MM-ss')}}</text>
				</view>
			<view class="orderInfo" @click="toDetail(item.paid,item.orderNumber,item._id)">
				<view class="picWrap">
					<image :src="item.pid.coverPic"></image>
				</view>
				<view class="proInfo">
					<text class="title">{{item.pid.title}}</text>
					<text class="viceTitle">{{item.pid.viceTitle}}</text>
				</view>
			</view>
				<view class="orderHandle">
					<text class="price">{{item.pid.price}}积分</text>
					<text class="num">x{{item.number}}</text>
					<text class="totalPrice">
						<text class="total">小计:</text>
						<text class="font">{{item.totalPrice}}积分</text>
					</text>
					<view class="btnWrap" v-if="item.paid">
						<u-button disabled type="success" size="mini" text="已完成" shape="circle"></u-button>
					</view>
					<view class="btnWrap" v-else>
						<u-button type="warning" size="mini" text="待支付" shape="circle"  @click="toDetail(item.paid,item.orderNumber,item._id)"></u-button>
					</view>
				</view>
			</view>
		</view>
		<u-empty
			v-else
			marginTop="140" 
			text="订单为空"
			icon="https://vkceyugu.cdn.bspapp.com/VKCEYUGU-8da6cc70-751c-428d-9aa0-6516abc1603f/b15c34e7-a9bc-4213-aba4-6728286996fc.png">
		</u-empty>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				orderList:[],
				isEmpty:false
			}
		},
		onReady(){
			this.getorderList()
		},
		methods:{
			async getorderList(){
				const {code,data} = await this.$axios.api.getOrderList()
				if(code === 200){
					this.orderList = data
					if(this.orderList.length>0){
					  this.isEmpty = false
					}else{
					  this.isEmpty = true
					}
				}
			},
			toDetail (paid,orderNum,id) {
				if (!paid) {
					const oid = []
					oid.push(id)
					uni.navigateTo({
						url:`/subcom-shop/OrderDetail/OrderDetail?orderInfo=${JSON.stringify({oid,orderNum})}`
					})
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
.container {
	width: 100%;
	height: 100%;
	display: flex;
	flex-direction: column;
	.orderList {
		min-height: 100%;
		background-color: rgb(244, 244, 244);
		padding: 20rpx;
		box-sizing: border-box;
		display: flex;
		flex-direction: column;
		.orderCard {
			height: auto;
			border-radius: 20rpx;
			background-color: #fff;
			padding: 0 20rpx;
			box-sizing: border-box;
			display: flex;
			flex-direction: column;
			margin-bottom: 20rpx;
			font-size: 24rpx;
			.orderNum,
			.orderCreated {
				height: 60rpx;
				line-height: 60rpx;
			}
			.orderInfo{
				height: auto;
				display: flex;
				justify-content: space-between;
				align-items: center;
				padding: 10rpx 0;
				box-sizing: border-box;
				border-top: 1rpx solid rgb(231, 231, 231);
				border-bottom: 1rpx solid rgb(231, 231, 231);
				.picWrap{
					width: 100rpx;
					height: 100rpx;
					image{
						width: 100%;
						height: 100%;
					}
				}
				.proInfo{
					flex: 1;
					height: 100rpx;
					display: flex;
					flex-direction: column;
					justify-content: space-around;
					align-items: center;
					.title{
						font-size: 26rpx;
						font-weight: bold;
					}
					.viceTitle{
						font-size: 24rpx;
						color: rgb(163, 163, 163);
					}
				}
			}
			.orderHandle{
				height: 80rpx;
				display: flex;
				justify-content: flex-end;
				align-items: center;
				text{
					margin-left: 20rpx;
				}
				.totalPrice{
					color: #ffaa00;
					font-size: 26rpx;
					font-weight: bold;
				}
				.btnWrap{
					width: 200rpx;
					margin-left: 20rpx;
				}
			}
		}
	}
}
</style>
